package org.jetlinks.pro.assets.impl;

import lombok.AllArgsConstructor;
import lombok.Generated;
import lombok.Getter;
import org.hswebframework.web.dict.EnumDict;
import org.jetlinks.pro.assets.AssetPermission;
import org.jetlinks.pro.assets.AssetType;
import org.jetlinks.pro.assets.crud.CrudAssetPermission;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor(staticName = "of")
@Getter
@Generated
public class UndefinedAssetType implements AssetType {
    private String id;

    @Override
    public String getName() {
        return id;
    }

    @Override
    public List<AssetPermission> getPermissions() {
        return Arrays.asList(CrudAssetPermission.values());
    }

    @Override
    public List<AssetPermission> getPermissions(long value) {
        return EnumDict.getByMask(this::getPermissions, value);
    }

    @Override
    public boolean hasPermission(long value, AssetPermission[] permissions) {
        return EnumDict.maskIn(value, permissions);
    }

    @Override
    public long createPermission(AssetPermission[] permissions) {
        return EnumDict.toMask(permissions);
    }

    @Override
    public long createAllPermission() {
        return createPermission(CrudAssetPermission.values());
    }

    @Override
    public List<AssetPermission> getPermissions(Collection<String> value) {
        return getPermissions()
            .stream()
            .filter(per->value.contains(per.getValue()))
            .collect(Collectors.toList());
    }
}
